<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>inversionmap_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_structs_inversionmap_test.js.html">inversionmap_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.structs.InversionMapTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.structs.InversionMapTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.structs.InversionMap&#39;);
<a name="line19"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line20"></a>
<a name="line21"></a>function testInversionWithDelta() {
<a name="line22"></a>  var alphabetNames = new goog.structs.InversionMap(
<a name="line23"></a>      [0, 97, 1, 1, 1, 20, 1, 1, 1],
<a name="line24"></a>      [null,
<a name="line25"></a>        &#39;LATIN SMALL LETTER A&#39;,
<a name="line26"></a>        &#39;LATIN SMALL LETTER B&#39;,
<a name="line27"></a>        &#39;LATIN SMALL LETTER C&#39;,
<a name="line28"></a>        null,
<a name="line29"></a>        &#39;LATIN SMALL LETTER X&#39;,
<a name="line30"></a>        &#39;LATIN SMALL LETTER Y&#39;,
<a name="line31"></a>        &#39;LATIN SMALL LETTER Z&#39;,
<a name="line32"></a>        null],
<a name="line33"></a>      true);
<a name="line34"></a>
<a name="line35"></a>  assertEquals(&#39;LATIN SMALL LETTER A&#39;, alphabetNames.at(97));
<a name="line36"></a>  assertEquals(&#39;LATIN SMALL LETTER Y&#39;, alphabetNames.at(121));
<a name="line37"></a>  assertEquals(null, alphabetNames.at(140));
<a name="line38"></a>  assertEquals(null, alphabetNames.at(0));
<a name="line39"></a>}
<a name="line40"></a>
<a name="line41"></a>function testInversionWithoutDelta() {
<a name="line42"></a>  var alphabetNames = new goog.structs.InversionMap(
<a name="line43"></a>      [0, 97, 98, 99, 100, 120, 121, 122, 123],
<a name="line44"></a>      [null,
<a name="line45"></a>        &#39;LATIN SMALL LETTER A&#39;,
<a name="line46"></a>        &#39;LATIN SMALL LETTER B&#39;,
<a name="line47"></a>        &#39;LATIN SMALL LETTER C&#39;,
<a name="line48"></a>        null,
<a name="line49"></a>        &#39;LATIN SMALL LETTER X&#39;,
<a name="line50"></a>        &#39;LATIN SMALL LETTER Y&#39;,
<a name="line51"></a>        &#39;LATIN SMALL LETTER Z&#39;,
<a name="line52"></a>        null],
<a name="line53"></a>      false);
<a name="line54"></a>
<a name="line55"></a>  assertEquals(&#39;LATIN SMALL LETTER A&#39;, alphabetNames.at(97));
<a name="line56"></a>  assertEquals(&#39;LATIN SMALL LETTER Y&#39;, alphabetNames.at(121));
<a name="line57"></a>  assertEquals(null, alphabetNames.at(140));
<a name="line58"></a>  assertEquals(null, alphabetNames.at(0));
<a name="line59"></a>}
<a name="line60"></a>
<a name="line61"></a>function testInversionWithoutDeltaNoOpt() {
<a name="line62"></a>  var alphabetNames = new goog.structs.InversionMap(
<a name="line63"></a>      [0, 97, 98, 99, 100, 120, 121, 122, 123],
<a name="line64"></a>      [null,
<a name="line65"></a>        &#39;LATIN SMALL LETTER A&#39;,
<a name="line66"></a>        &#39;LATIN SMALL LETTER B&#39;,
<a name="line67"></a>        &#39;LATIN SMALL LETTER C&#39;,
<a name="line68"></a>        null,
<a name="line69"></a>        &#39;LATIN SMALL LETTER X&#39;,
<a name="line70"></a>        &#39;LATIN SMALL LETTER Y&#39;,
<a name="line71"></a>        &#39;LATIN SMALL LETTER Z&#39;,
<a name="line72"></a>        null]);
<a name="line73"></a>
<a name="line74"></a>  assertEquals(&#39;LATIN SMALL LETTER A&#39;, alphabetNames.at(97));
<a name="line75"></a>  assertEquals(&#39;LATIN SMALL LETTER Y&#39;, alphabetNames.at(121));
<a name="line76"></a>  assertEquals(null, alphabetNames.at(140));
<a name="line77"></a>  assertEquals(null, alphabetNames.at(0));
<a name="line78"></a>}
<a name="line79"></a>
<a name="line80"></a>function testInversionMapSplice1() {
<a name="line81"></a>  var alphabetNames = newAsciiMap();
<a name="line82"></a>  alphabetNames.spliceInversion(
<a name="line83"></a>      [99, 105, 114], [&#39;XXX&#39;, &#39;YYY&#39;, &#39;ZZZ&#39;]);
<a name="line84"></a>  assertEquals(&#39;LATIN SMALL LETTER B&#39;, alphabetNames.at(98));
<a name="line85"></a>  assertEquals(&#39;XXX&#39;, alphabetNames.at(100));
<a name="line86"></a>  assertEquals(&#39;ZZZ&#39;, alphabetNames.at(114));
<a name="line87"></a>  assertEquals(&#39;ZZZ&#39;, alphabetNames.at(119));
<a name="line88"></a>  assertEquals(&#39;LATIN SMALL LETTER X&#39;, alphabetNames.at(120));
<a name="line89"></a>}
<a name="line90"></a>
<a name="line91"></a>function testInversionMapSplice2() {
<a name="line92"></a>  var alphabetNames = newAsciiMap();
<a name="line93"></a>  alphabetNames.spliceInversion(
<a name="line94"></a>      [105, 114, 121], [&#39;XXX&#39;, &#39;YYY&#39;, &#39;ZZZ&#39;]);
<a name="line95"></a>  assertEquals(null, alphabetNames.at(104));
<a name="line96"></a>  assertEquals(&#39;XXX&#39;, alphabetNames.at(105));
<a name="line97"></a>  assertEquals(&#39;YYY&#39;, alphabetNames.at(120));
<a name="line98"></a>  assertEquals(&#39;ZZZ&#39;, alphabetNames.at(121));
<a name="line99"></a>  assertEquals(&#39;LATIN SMALL LETTER Z&#39;, alphabetNames.at(122));
<a name="line100"></a>}
<a name="line101"></a>
<a name="line102"></a>function testInversionMapSplice3() {
<a name="line103"></a>  var alphabetNames = newAsciiMap();
<a name="line104"></a>  alphabetNames.spliceInversion(
<a name="line105"></a>      [98, 99], [&#39;CHANGED LETTER B&#39;, &#39;CHANGED LETTER C&#39;]);
<a name="line106"></a>  assertEquals(&#39;LATIN SMALL LETTER A&#39;, alphabetNames.at(97));
<a name="line107"></a>  assertEquals(&#39;CHANGED LETTER B&#39;, alphabetNames.at(98));
<a name="line108"></a>  assertEquals(&#39;CHANGED LETTER C&#39;, alphabetNames.at(99));
<a name="line109"></a>  assertEquals(&#39;LATIN SMALL LETTER D&#39;, alphabetNames.at(100));
<a name="line110"></a>  assertEquals(null, alphabetNames.at(101));
<a name="line111"></a>}
<a name="line112"></a>
<a name="line113"></a>function testInversionMapSplice4() {
<a name="line114"></a>  var alphabetNames = newAsciiMap();
<a name="line115"></a>  alphabetNames.spliceInversion(
<a name="line116"></a>      [98, 1], [&#39;CHANGED LETTER B&#39;, &#39;CHANGED LETTER C&#39;],
<a name="line117"></a>      true /* delta mode */);
<a name="line118"></a>  assertEquals(&#39;LATIN SMALL LETTER A&#39;, alphabetNames.at(97));
<a name="line119"></a>  assertEquals(&#39;CHANGED LETTER B&#39;, alphabetNames.at(98));
<a name="line120"></a>  assertEquals(&#39;CHANGED LETTER C&#39;, alphabetNames.at(99));
<a name="line121"></a>  assertEquals(&#39;LATIN SMALL LETTER D&#39;, alphabetNames.at(100));
<a name="line122"></a>  assertEquals(null, alphabetNames.at(101));
<a name="line123"></a>}
<a name="line124"></a>
<a name="line125"></a>function testInversionMapSplice5() {
<a name="line126"></a>  var map = new goog.structs.InversionMap(
<a name="line127"></a>      [0, 97, 98, 99],
<a name="line128"></a>      [null,
<a name="line129"></a>       &#39;LATIN SMALL LETTER A&#39;,
<a name="line130"></a>       &#39;LATIN SMALL LETTER B&#39;,
<a name="line131"></a>       &#39;LATIN SMALL LETTER C&#39;]);
<a name="line132"></a>  map.spliceInversion(
<a name="line133"></a>      [98], [&#39;CHANGED LETTER B&#39;]);
<a name="line134"></a>  assertEquals(&#39;LATIN SMALL LETTER A&#39;, map.at(97));
<a name="line135"></a>  assertEquals(&#39;CHANGED LETTER B&#39;, map.at(98));
<a name="line136"></a>  assertEquals(&#39;LATIN SMALL LETTER C&#39;, map.at(99));
<a name="line137"></a>
<a name="line138"></a>  assertArrayEquals([0, 97, 98, 99], map.rangeArray);
<a name="line139"></a>}
<a name="line140"></a>
<a name="line141"></a>function newAsciiMap() {
<a name="line142"></a>  return new goog.structs.InversionMap(
<a name="line143"></a>      [0, 97, 98, 99, 100, 101, 120, 121, 122, 123],
<a name="line144"></a>      [null,
<a name="line145"></a>        &#39;LATIN SMALL LETTER A&#39;,
<a name="line146"></a>        &#39;LATIN SMALL LETTER B&#39;,
<a name="line147"></a>        &#39;LATIN SMALL LETTER C&#39;,
<a name="line148"></a>        &#39;LATIN SMALL LETTER D&#39;,
<a name="line149"></a>        null,
<a name="line150"></a>        &#39;LATIN SMALL LETTER X&#39;,
<a name="line151"></a>        &#39;LATIN SMALL LETTER Y&#39;,
<a name="line152"></a>        &#39;LATIN SMALL LETTER Z&#39;,
<a name="line153"></a>        null]);
<a name="line154"></a>}
</pre>


</body>
</html>
